<?php
/**
 * Bdat Site development
 * @author Will Skates
 */

/*----------------------------------------------------------------------------------------------------*/

/**
 * Outline of properties and functionality required to make and access user profile information within the system.
 * @author Will Skates
 */
class UserProfile extends CI_Model {
	
	public $twitter;
	public $flickr;
	public $youtube;
	public $name;
	public $bio;
	public $gradyear;
	public $feed;
	public $isguesttweeter;
	public $email;
	public $userid;
	
	public static $fields;
	
	/**
	 * Constructor creates a profile object from the data given to it by the class that instanciated it (mostly User).
	 * @param 	Array	$info
	 * @return	Void
	 */
	public function __construct( $info )
	{
		parent::__construct();
		
		$info = (Array)$info;
		if ( !isset(self::$fields) ) { self::$fields = array_keys((Array)$this); }
		
		foreach ( $info as $k=>$v ) {
			
			//Make sure the data we are being given is valid for a user profile.
			if ( !in_array( $k, self::$fields ) ) { continue; }
			
			switch ($k) {
				
				default:
					$this->$k = $v;
				break;
				
				case 'isguesttweeter':
					$this->$k = (Boolean)$v;
				break;
				
				case 'userid':
				case 'gradyear':
					$this->$k = (Int)$v;
				break;
				
				
			}
			
			
			
		}
		
	}
	
	/*----------------------------------------------------------------------------------------------------*/
	
	/**
	 * Draw the html version of the users profile for the admin cms.
	 * @return	String		$html	-	The html text.
	 * Enter description here ...
	 */
	public function draw()
	{
		$sql = 'SELECT uid,name FROM user_roles';
		$result = $this->db->query($sql)->result();
		$result = reset(array_chunk($result, count($result)));
		
		$u = new User();
		return $this->load->view('admin/profile',array('info'=>$u->make($this->userid),'roles'=>$result),true);
	}

	/*----------------------------------------------------------------------------------------------------*/
	
}